package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConst;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/menu")
@Slf4j
public class MenuController {

    @Reference
    private MenuService menuService;

    //菜单编辑
    @RequestMapping("/menuEdit")
    public Result edit(@RequestBody Menu menu){
        log.debug("menuEdit:"+menu);
        menuService.edit(menu);
        log.debug("菜单修改成功");
        return new Result(true,MessageConst.EDIT_MENU_SUCCESS);
    }

    //菜单编辑根据id回显数据
    @RequestMapping("/menuEditById")
    public Result menuEditById(Integer id){
        log.debug("menuEditById:"+id);
        Menu menu = menuService.editById(id);
        log.debug("根据id查询菜单成功");
        return new Result(true,MessageConst.QUERY_MENU_SUCCESS,menu);
    }

    //根据id删除菜单
    @RequestMapping("/menuDeleteById")
    public Result menuDeleteById(Integer id){
        log.debug("menuDeleteById:"+id);
        menuService.deleteById(id);
        log.debug("根据id删除菜单成功");
        return new Result(true,MessageConst.DELETE_MENU_SUCCESS);
    }

    @RequestMapping("/findMenuPage")
    public Result findMenuPage(@RequestBody QueryPageBean queryPageBean) {
        log.debug("controller:" + queryPageBean);
        PageResult pageResult = menuService.findMenuPage(queryPageBean);
        log.debug("PageResult:" + pageResult);
        return new Result(true, MessageConst.QUERY_MENULIST_SUCCESS,pageResult);
    }



}
